'use strict';
const mongoose = require('mongoose');
const config = require('../config/config.unittest.js')({});
const fs = require('fs');
const readline = require('readline');
const moment = require('moment');
const _ = require('lodash');

let ParserBetter = require('../app/utils/rss/parser');
let parserBetter = new ParserBetter({timeout: 10000});

const UserModel = require('../app/model/User')({
  mongoose,
});
const TopicModel = require('../app/model/Topic')({
  mongoose,
});
const TopicCollectModel = require('../app/model/TopicCollect')({
  mongoose,
});

mongoose.connect(config.mongoose.url, config.mongoose.options, function (err) {
  if (err) {
    console.error('connect to %s error: ', config.mongoose, err.message);
    process.exit(1);
  }
});

main();

async function main() {
  await crud();
  process.exit(0);
}


async function crud() {
  const loginname = '问题青年';
  const url = 'https://www.xiaoyuzhoufm.com/podcast/6049a089b875ad149b233c55'

  const user = await UserModel.findOne({loginname});
  if (!JSON.stringify(user.froms).includes('中文播客榜')) {
    user.froms.unshift({name: '中文播客榜', url});
    await user.save();
    console.log('success...');
  } else {
    console.log('已经有中文播客榜...', JSON.stringify(user.froms));
  }
}
